package com.example.demo2;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("H")
@RestController
public class Header {
    @RequestMapping("h1")
    public String h1(HttpServletRequest request){
        String userAgent=request.getHeader("User-Agent");
        return "从header中获取userAgent:"+userAgent;
    }

    @RequestMapping("h2")
    public String h2(@RequestHeader("user-Agent") String userAgent){
        return "从header中获取userAgent:"+userAgent;
    }



}
